<%--
  Created by IntelliJ IDEA.
  User: 张洪瑞
  Date: 2021-6-24  0024
  Time: 下午 14:02:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ueditor/ueditor.all.min.js"></script>
</head>
<body style="padding: 10px 15px 0px 15px">
<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" placeholder="请输入公告类型" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" lay-verify="required" placeholder="请输入公告标题" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" placeholder="备注（选填）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <textarea id="container" name="content" style="margin-top: 20px;height: 250px;"></textarea>

    <div class="layui-form-item" style="margin-top: 10px;margin-left: 20px;">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">添加</button>
    </div>
</form>

</body>
<script>
    var ue = UE.getEditor("container");

    layui.use(['form', 'jquery','layer'], function(){
        var form = layui.form
            ,$ = layui.jquery
            ,layer = layui.layer;

        //监听提交
        form.on('submit(demo1)', function(data){
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            var json = {"json":JSON.stringify(data.field)};
            $.post("addNotice.do",json,function (data) {
                if (data != "0"){
                    layer.msg("添加成功!<br>3秒后刷新！",{icon:1});
                }else {
                    layer.msg("添加失败!<br>3秒后刷新！",{icon:5})
                }
                //创建一个定时器
                var myTime = setInterval(function () {  //3秒后刷新本页面
                    window.location.href="addNotice.jsp";
                },3000);
            })
            return false;
        });

    });
</script>
</html>
